<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>
<body>
	<form class="layui-form" action="" lay-filter="xc_config-add-form" style="margin-top: 20px;">
		<input th:value="${session.formToken}" name="formToken" type="hidden" />
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">分组：</label>
			<div class="layui-input-block">
				<select name="groupId" lay-verify="required">
					<option value="">请选择分组</option>
					<option th:each="group:${groups}" th:value="${group.id}" th:text="${group.name}"></option>
				</select>
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">作者：</label>
			<div class="layui-input-block">
				<input id="author" name="author" th:value="${session.user.nickName}" placeholder="请输入作者"
					class="layui-input" lay-verify="required" autocomplete="off">
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">包名：</label>
			<div class="layui-input-block">
				<input id="packageName" name="packageName" placeholder="请输入包名" class="layui-input"
					lay-verify="required" autocomplete="off">
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">标题：</label>
			<div class="layui-input-block">
				<input id="title" name="title" placeholder="请输入标题" class="layui-input" lay-verify="required"
					autocomplete="off">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">地址：</label>
				<div class="layui-input-inline" style="width: 150px;">
					<input id="host" name="host" placeholder="主机" autocomplete="off" class="layui-input"
						lay-verify="required">
				</div>
				<div class="layui-form-mid">:</div>
				<div class="layui-input-inline" style="width: 100px;">
					<input id="port" name="port" placeholder="端口" value="3306" autocomplete="off"
						class="layui-input" lay-verify="required">
				</div>
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">数据库：</label>
			<div class="layui-input-block">
				<input id="database" name="database" placeholder="请输入数据库名称" class="layui-input"
					lay-verify="required" autocomplete="off">
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">用户名：</label>
			<div class="layui-input-block">
				<input id="username" name="username" placeholder="请输入用户名" class="layui-input"
					lay-verify="required" autocomplete="off">
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<label class="layui-form-label">密码：</label>
			<div class="layui-input-block">
				<input id="password" name="password" placeholder="请输入密码" class="layui-input"
					lay-verify="required" autocomplete="off">
			</div>
		</div>
		<!--  -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="xc_config-add">立即提交</button>
				<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="xc_config-test">测试连接</button>
				<span id="msg" style="margin-left: 30px;"></span>
			</div>
		</div>
	</form>
	<div th:include="include::footer"></div>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
		layui.use([ 'layer', 'jquery', 'form' ], function() {
			var $ = layui.jquery;
			var layer = layui.layer;
			var form = layui.form;
			//监听提交
			form.on('submit(xc_config-add)', function(data) {
				//提交数据data.field
				ajaxPostLoad("/xc/config/save", data.field);
				return false;
			});
			//测试连接
			form.on('submit(xc_config-test)', function(data) {
				//提交数据data.field
				$.ajax({
					cache : true,
					type : "POST",
					url : "/generator/test",
					data : data.field,
					success : function(data) {
						if (data.retCode == '0000') {
							$("#msg").css("color", "green");
						} else {
							$("#msg").css("color", "red");
						}
						$("#msg").html(data.retMsg);
					},
					error : function(request) {
						layer.alert("请检查参数");
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>